package com.controller.buying 
{
	
	
	import com.model.valueObjects.VoAmendHeader;
	import com.service.PoAmend;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class POamendmentController extends AbstractController
	{
		
		[Inject]
		public var poAmendmentService:PoAmend;
		
		public function POamendmentController()
		{
			super();
		}
		
		[EventHandler(event="PoAmendmentEvent.GET_ALL")]
		public function getAll():void{
			sh.executeServiceCall(poAmendmentService.getAllPoAmends(),getAllResult, handleFault );
			
		}
		private function getAllResult(event:ResultEvent):void
		{
			CursorManager.removeBusyCursor();
			model.currentBuyTableIndex=2;
			model.poAmendmentHeaderList=event.result as ArrayCollection;
			model.poAmendmentHeaderList.refresh();
		}
		[EventHandler(event="PoAmendmentEvent.ADD", properties="poamendment_vo")]
		public function add(poamendment_vo:VoAmendHeader):void
		{
			model.currentBuyFormsIndex=0;	
			sh.executeServiceCall(poAmendmentService.addNewPoAmend(poamendment_vo),addResult, handleFault );	
		}
		
		private function addResult(event:ResultEvent):void
		{
			Alert.show( "Befor PO Amendment  added" );
			getAll();
		//odel.goodsReceivedList.addItem(event.result as VoGoodsReceived)
	//	model.goodsReceivedList.refresh();
		Alert.show( "PO Amendment  added" );	
		}
		
		private function handleFault(event:FaultEvent):void
		{
			getAll();
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}